import useLoginStore from '@/store/login'
import { storeToRefs } from 'pinia'
import { computed } from 'vue'

export function usePermission(pageName: string) {
  const loginStore = useLoginStore()
  const { permission } = storeToRefs(loginStore)

  const isCreate = computed(() => permission.value.find((o) => o.includes(`${pageName}:create`)))
  const isDelete = computed(() => permission.value.find((o) => o.includes(`${pageName}:delete`)))
  const isUpdate = computed(() => permission.value.find((o) => o.includes(`${pageName}:update`)))
  const isQuery = computed(() => permission.value.find((o) => o.includes(`${pageName}:query`)))

  return {
    isCreate,
    isDelete,
    isUpdate,
    isQuery
  }
}
